const app = getApp()

Page({
    data:{
        show:false
    },
    onLoad(){
    //wxreq回车
    var self = this;
    wx.request({
    //    url: 'https://www.easy-mock.com/mock/5bac7411b328c27d98eb1435/test02/test01',
    url:"https://douban.uieee.com/v2/movie/top250",
       header: {
           'Content-Type': 'json'
       },
       success: function(res) {
        //    var data = res.data.data;
        //    self.setData({
        //        data,
        //        top:3
        //    });
        self.handleData(res);
       }
   });
  },
  handleData(res){
      var data = [];
      var subject = res.data.subjects;
      console.log(subject);
      for(let key in subject){
          var name = subject[key].title;
          var average = subject[key].rating.average;
          var imgUrl = subject[key].images.small;
          var id = subject[key].id;
          var temp = {};
          temp.name=name;
          temp.average=average;
          temp.imgUrl= imgUrl;
          temp.id = id;
          data.push(temp);
      }
      this.setData({
          data,
          show:true
      })
  },
  handleClick(event){
      var id = event.currentTarget.dataset.id;
      console.log(id);
      wx.navigateTo({
          url:'/pages/movie-detail/movie-detail?id='+id
      })
  }
});